package com.baidu.videoseries;

import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.v4.app.FragmentManager;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.kvin.toolkit.activity.OnBindInit;

public class ToolbarActivity extends AppCompatActivity implements OnBindInit {
    private android.widget.TextView titleText;
    private Toolbar toolbar;
    private FloatingActionButton fab;
    private boolean isInitialized;
    protected int mIndex;
    protected Intent mIntent;

    protected FragmentManager mManager;

    private OnFabClickListener mOnFabClickListener;
    private OnNavClickListener mOnNavClickListener;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        super.setContentView(R.layout.activity_toolbar);
        this.fab = (FloatingActionButton) findViewById(R.id.fab);
        this.toolbar = (Toolbar) findViewById(R.id.toolbar);
        this.toolbar.setTitle("");
//        this.toolbar.setNavigationIcon(R.mipmap.icon_pop_last);
        this.titleText = (TextView) findViewById(R.id.title_text);
        setSupportActionBar(toolbar);

        this.isInitialized = false;
        this.mManager = getSupportFragmentManager();
        initConfig();
    }

    @Override
    protected void onStart() {
        super.onStart();
        if (!isInitialized) {
            isInitialized = true;
            initNav();
            init();
        }
    }

    private void initConfig() {
        this.fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mOnFabClickListener != null)
                    mOnFabClickListener.onFabClick(v);
            }
        });

        this.toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (mOnNavClickListener != null)
                    mOnNavClickListener.onFabClick(view);
            }
        });
    }

    @Override
    public void init() {

    }

    @Override
    public void initNav() {

    }

    @Override
    public void initDialog() {

    }

    @Override
    public void loadingData(int pageNum) {

    }

    /**
     * hide action bar
     */
    protected void hideActionbar() {
        ActionBar bar = this.getSupportActionBar();
        if (bar != null)
            bar.hide();
    }

    /**
     * request landscape
     */
    protected void requestLandScape() {
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);
    }

    /**
     * hide  mStatus bar
     */
    protected void hideStatusBar() {
        this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    }


    /**
     * set title
     */
    public void setTitle(String title) {
        this.titleText.setText(title);
    }

    /**
     * set on fab click listener
     *
     * @param mOnFabClickListener
     */
    public void setOnFabClickListener(OnFabClickListener mOnFabClickListener) {
        this.mOnFabClickListener = mOnFabClickListener;
    }

    /**
     * set fab visible
     */
    public void setFabVisibility(int visibility) {
        this.fab.setVisibility(visibility);
    }

    /**
     * set action bar visible
     */
    public void setActionBarVisible(int visibility) {
        this.toolbar.setVisibility(View.GONE);
    }

    public interface OnFabClickListener {
        void onFabClick(View v);
    }

    public void setOnNavClickListener(OnNavClickListener onNavClickListener) {
        this.mOnNavClickListener = onNavClickListener;
    }

    public interface OnNavClickListener {
        void onFabClick(View v);
    }


}
